<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/9/14
 * Time: 18:33
 */

namespace Service;

use cli\progress\Bar;

class LoadingService
{
	public $msg='加载中';
	protected $Bar=false;
	protected $total = 100;
	protected $increment = 1;

	protected $loadStatus = false; //当前加载状态
	
	public function __construct($msg)
	{
		$this->msg = $msg;
	}
	
	public function start(){
		$this->Bar = new Bar($this->msg,$this->total);
		$this->loadStatus = true;
		return $this->Bar->display();
	}
	
	public function tick(){
		$this->Bar->tick($this->increment,$this->msg);
		return $this;
	}
	
	public function close(){
		if($this->Bar){
			$this->Bar->finish();
		}
		$this->loadStatus = false;
		return true;
	}
	
	public function setMsg($msg = null){
		if($msg){
			$this->msg =  $msg;
		}
		return $this;
	}
	
	public function setTotal($total=100){
		$this->total =  $total;
		return $this;
	}
	public function setTick($increment){
		$this->increment = $increment;
		$this->Bar->tick($this->increment,$this->msg);
		return $this;
	}
	
	public function getLoadingStatus(){
		return $this->loadStatus;
	}
	

}